package com.dragon.mmochat.message;

import java.util.ArrayList;
import java.util.List;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.enumType.MmochatPropType;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.dragon.mmochat.service.MmochatMainService;
import com.skymobi.buffer.SkymobiBuffer;
import com.skymobi.message.SkymobiProtocolMessage;

public class Mmochat_10_16S extends SkymobiProtocolMessage {
	List<Integer> onlines = new ArrayList<Integer>();
	List<Integer> offlines = new ArrayList<Integer>();

	public Mmochat_10_16S() {
		setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_16);
	}

	@Override
	protected void encodeBody(SkymobiBuffer out) {
		out.put((byte) onlines.size());
		for (Integer roleId : onlines) {
			out.putInt(roleId);

			MmochatPlayer p = MmochatMainService.players.get(roleId);
			if (p != null) {
				if (p.hasPropEffect(MmochatPropType.会员周卡.getEffectKey())) {
					out.put((byte) 1);
				} else {
					out.put((byte) 0);
				}
			} else {
				out.put((byte) 0);
			}
		}

		out.put((byte) offlines.size());
		for (Integer roleId : offlines) {
			out.putInt(roleId);
		}
	}

	public void setOnlines(List<Integer> onlines) {
		this.onlines = new ArrayList<Integer>(onlines);
	}

	public void setOfflines(List<Integer> offlines) {
		this.offlines = new ArrayList<Integer>(offlines);
	}

}
